package com.vodone.v1pin.index.pm
{
	
	
	import com.vodone.v1pin.index.delegate.PicConvertUtil;
	import com.vodone.v1pin.index.delegate.PicDelegate;
	
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;

	/**
	* 请求成功时派发 
	*/	
	[Event(name="picComplete")]
	/**
	* 请求失败时派发
	*/	
	[Event(name="fault")]
	/**
	* 开始请求时派发
	*/	
	[Event(name="startLoad")]
	
	public class PicPM extends EventDispatcher
	{
		public static const STARTLoad:String = "startLoad";
		public static const FAULT:String = "fault";
		
		/**
		 * 首页大图 
		 */		
		public static const MAIN:String = "0";
		/**
		 * 新品推荐
		 */		
		public static const NEWPRODUCT:String = "1";
		/**
		 * 特惠专区 
		 */		
		public static const THZQ:String = "2";
		/**
		 * 热门推荐 
		 */		
		public static const RMTJ:String = "3";
		/**
		 * 热销商品 （需要类别id） 
		 */		
		public static const RXSP:String = "4";
		
		
		/**
		 * 推荐商品
		 */		
		public static const TJSP:String = "5";
		/**
		 * 推荐品牌
		 */		
		public static const TJPP:String = "6";
		/**
		 * 品味推荐
		 */		
		public static const PWTJ:String = "7";
		/**
		 * 折扣专区
		 */		
		public static const DISCOUNT:String = "8";
		/**
		 * 活动专区
		 */		
		public static const ACTIVE:String = "8";
		
		public var picList:Array;
		
		public var type:String;
		public var id:String;
		public function PicPM(target:IEventDispatcher=null)
		{
			super(target);
		}
		
		public function doSearch( type:String , id:String = "0" , num:int = 0):void
		{
			this.type = type;
			this.id = id;
			PicDelegate.getBigPicList(resultHandler,type,id,num,faultHandler);
			this.dispatchEvent( new Event( STARTLoad ) ); 
		}
		
		public function resultHandler( obj:Object ):void
		{
			if(this.type == "1"){
				trace(this.type);
			}
			picList = PicConvertUtil.getPicList( obj );
			this.dispatchEvent( new Event( "picComplete" ));
		}
		
		private function faultHandler( obj:Object ):void
		{
			this.dispatchEvent( new Event( "fault" ));
		}
	}
}